import 'package:cbec_app/components/base/base_image.dart';
import 'package:cbec_app/components/base/base_nav_bar.dart';
import 'package:cbec_app/components/base/base_page.dart';
import 'package:cbec_app/components/common/common_style.dart';
import 'package:cbec_app/components/common/count_down_timer.dart';
import 'package:cbec_app/components/common/not_found.dart';
import 'package:cbec_app/pages/my/controller/bargaining_order_ctr.dart';
import 'package:cbec_app/utils/Tools.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

//砍价详情
class BragainingDetail extends GetView<BargainingOrderController> {
  const BragainingDetail({super.key});

  @override
  Widget build(BuildContext context) {
    return GetBuilder<BargainingOrderController>(builder: (controller) {
      return BasePage(
        title: "砍价详情",
        navBgColor: Colors.white,
        bodyColor: Tools.fromHex('#ed7448'),
        iconType: IconType.back,
        children: [
          Container(
            margin: EdgeInsets.only(top: 50.w),
            child: Stack(
              children: [
                //主box
                Positioned(
                    child: Container(
                  width: 375.w,
                  margin: EdgeInsets.only(top: 34.w, left: 8.w, right: 8.w),
                  decoration: border_radis(Colors.white),
                  child: Column(
                    children: [
                      SizedBox(height: 45.h),
                      Text("【我发现一个好货，快来呼朋唤友砍价吧】", style: setTextStyle(13, FontWeight.w400, Tools.fromHex("#333333"))),
                      SizedBox(height: 20.h),
                      Container(
                        padding: EdgeInsets.only(left: 20.w, right: 20.w),
                        child: Row(
                          children: [
                            if (controller.detail?['img'] != null)
                              BaseImage(
                                url: controller.detail?['img'],
                                width: 100.w,
                                height: 100.w,
                                borderRadius: BorderRadius.circular(5.w),
                              ),
                            Container(
                              height: 100.w,
                              margin: EdgeInsets.only(left: 10.w),
                              width: 195.w,
                              child: Column(
                                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                children: [
                                  if (controller.detail?['goodsName'] != null) ...[
                                    SizedBox(
                                      // color: Colors.red,
                                      width: double.infinity,
                                      child: Text(controller.detail?['goodsName'].trimLeft()),
                                    )
                                  ],
                                  Row(
                                    mainAxisAlignment: MainAxisAlignment.start,
                                    children: [
                                      Row(
                                        children: [
                                          Text("底价:", style: setTextStyle(14, FontWeight.w400, Tools.fromHex("#333333"))),
                                          Text("￥", style: setTextStyle(10, FontWeight.w400, Tools.fromHex("#333333"))),
                                          if (controller.detail != null) Text(controller.detail!['priceLimit'].toString().split(".").first, style: setTextStyle(18, FontWeight.w700, Tools.fromHex("#333333"))),
                                          Text(".${controller.detail?['priceLimit'].toString().split(".").last}", style: setTextStyle(10, FontWeight.w400, Tools.fromHex("#333333")))
                                        ],
                                      ),
                                      const SizedBox(width: 5),
                                      Container(
                                        margin: EdgeInsets.only(right: 30.w),
                                        child: Text("¥${controller.detail?['priceOld'].toString()}", style: setTextStyle(14, FontWeight.w400, Tools.fromHex("#999999"), decoration: TextDecoration.lineThrough)),
                                      )
                                    ],
                                  )
                                ],
                              ),
                            ),
                          ],
                        ),
                      ),

                      //已砍多少
                      SizedBox(height: 20.w),
                      Container(
                        decoration: border_radis(Tools.fromHex("#FFF0E9"), radiusValue: 20),
                        width: 200.w,
                        height: 28.w,
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            Text("已砍", style: setTextStyle(14, FontWeight.w400, Tools.fromHex("#FF955D"))),
                            Text(controller.detail!['priceHaggleTotal'].toString(), style: setTextStyle(14, FontWeight.w400, Tools.fromHex("#F83F2D"))),
                            Text("元,还差", style: setTextStyle(14, FontWeight.w400, Tools.fromHex("#FF955D"))),
                            Text(controller.detail!['priceLeft'].toString(), style: setTextStyle(14, FontWeight.w400, Tools.fromHex("#F83F2D"))),
                            Text("元", style: setTextStyle(14, FontWeight.w400, Tools.fromHex("#FF955D"))),
                          ],
                        ),
                      ),
                      //进度条
                      SizedBox(height: 25.w),
                      Container(
                        margin: EdgeInsets.only(left: 10.w, right: 10.w),
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(10.0.w), // 设置圆角的半径
                        ),
                        clipBehavior: Clip.hardEdge,
                        child: LinearProgressIndicator(
                          backgroundColor: Tools.fromHex("#F3F3F3"), // 背景颜色
                          valueColor: AlwaysStoppedAnimation<Color>(Tools.fromHex("#FF722B")), // 进度条颜色
                          value: controller.detail?['cutPercent'], // 进度值，0.0表示无进度，1.0表示完全完成
                          minHeight: 10.0, // 最小高度
                        ),
                      ),
                      //剩余时间
                      Container(
                        margin: EdgeInsets.only(top: 20.w),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            Text("剩余时间:", style: setTextStyle(14, FontWeight.w400, Tools.fromHex("#3D3D3D"))),
                            SizedBox(width: 10.w),
                            controller.detail?['ldTimeStamp'] != null
                                ? CountDownTimer(
                                    timeStamp: controller.detail?['ldTimeStamp'] * 1000,
                                    countDownStyle: CountDownStyle.box,
                                    boxBackgroundColor: Tools.fromHex("#FFB089"),
                                    colonColor: Tools.fromHex("#3D3D3D"),
                                    style: setTextStyle(14, FontWeight.w400, Tools.fromHex("#3D3D3D")),
                                  )
                                : SizedBox()
                          ],
                        ),
                      ),
                      //直接购买的按钮

                      (controller.detail != null && controller.detail!['mineHaggle'] != null && controller.detail!['mineHaggle'] == 1)
                          ? Container(
                              margin: EdgeInsets.only(top: 20.w),
                              child: Row(mainAxisAlignment: MainAxisAlignment.center, children: [
                                Visibility(
                                  visible: (controller.detail!['canBuy'] == 1),
                                  child: TextButton(
                                    onPressed: () {
                                      // 点击按钮时执行的操作
                                      controller.jumpFillOrder();
                                    },
                                    style: ButtonStyle(
                                      // 移除按钮的内边距和背景颜色
                                      padding: WidgetStateProperty.all(EdgeInsets.zero),
                                      backgroundColor: WidgetStateProperty.all(Colors.transparent),
                                      foregroundColor: WidgetStateProperty.all(Colors.transparent),
                                      overlayColor: WidgetStateProperty.all(Colors.transparent),
                                      shadowColor: WidgetStateProperty.all(Colors.transparent),
                                      side: WidgetStateProperty.all(BorderSide.none),
                                    ),
                                    child: const Text(
                                      '直接购买',
                                      style: TextStyle(color: Colors.black), // 设置文本颜色为黑色
                                    ),
                                  ),
                                ),
                                Visibility(
                                  visible: controller.detail!['haggleStatus'] == 0,
                                  child: solidButton("邀请好友", width: (controller.detail!['haggleStatus'] == 0 && controller.detail!['canBuy'] == 1) ? 250 : 339, radius: 30, backgroundColor: Tools.fromHex("#F57140"), () {
                                    controller.shareMiniProgram();
                                  }),
                                ),
                              ]),
                            )
                          : const SizedBox(),
                      //文本
                      Container(
                        margin: EdgeInsets.only(top: 10.w),
                        child: Column(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            Text("听说分享到群聊砍价几率更高哦～", style: setTextStyle(14, FontWeight.w400, Tools.fromHex("#FF955D"))),
                            Row(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: [Text("砍价详情可前往", style: setTextStyle(14, FontWeight.w400, Tools.fromHex("#FF955D"))), Text("我的-砍价", style: setTextStyle(14, FontWeight.w400, Tools.fromHex("#F83F2D"))), Text("查看", style: setTextStyle(14, FontWeight.w400, Tools.fromHex("#FF955D")))],
                            )
                          ],
                        ),
                      ),
                      SizedBox(height: 15.w)
                    ],
                  ),
                )),
                //头像
                Positioned(
                    top: 1,
                    left: MediaQuery.of(context).size.width / 2 - 34.w,
                    child: Container(
                      decoration: border_radis(Colors.white, radiusValue: 68.w / 2),
                      padding: EdgeInsets.all(0.5.w),
                      child: (controller.detail != null && controller.detail?['avatar'] != null)
                          ? BaseImage(
                              url: controller.detail?['avatar'],
                              width: 68.w,
                              height: 68.w,
                              borderRadius: BorderRadius.circular(68 / 2),
                            )
                          : const SizedBox(),
                    )),
              ],
            ),
          ),

          //好友助力列表

          Container(
            margin: EdgeInsets.only(top: 15.w),
            child: Stack(
              children: [
                //列表容器
                Positioned(
                    child: Container(
                  margin: EdgeInsets.only(top: 15.w, left: 8.w, right: 8.w, bottom: 15.w),
                  decoration: border_radis(Colors.white),
                  // height: 300.h,
                  child: (controller.detail != null && controller.detail?['haggleList'] != null && controller.detail?['priceHaggleTotal'] != null)
                      ? Column(
                          children: [
                            SizedBox(height: 25.w),
                            Text("共有${controller.detail?['haggleList'].length}个好友帮你砍掉${controller.detail?['priceHaggleTotal']}元", style: setTextStyle(12, FontWeight.w400, Tools.fromHex("#FF955D"))),
                            Container(
                              padding: EdgeInsets.only(left: 10.w, right: 10.w, bottom: 10.w),
                              child: controller.detail?['haggleList'].isNotEmpty
                                  ? ListView.builder(
                                      itemCount: controller.detail?['haggleList'].length,
                                      shrinkWrap: true,
                                      itemBuilder: (context, index) {
                                        final Map item = controller.detail?['haggleList'][index];
                                        return helpListItem();
                                      })
                                  : const NotFound(txt: "目前还没有人帮你砍价,去邀请吧 ~"),
                            )
                          ],
                        )
                      : const SizedBox(),
                )),

                Positioned(
                    top: 1,
                    left: MediaQuery.of(context).size.width / 2 - 71.w,
                    child: Container(
                      alignment: Alignment.center,
                      color: Tools.fromHex("#FC5920"),
                      width: 142.w,
                      height: 31.w,
                      child: Text("好友助力列表", style: setTextStyle(17, FontWeight.w400, Tools.fromHex("#FFFFFF"))),
                    ))
              ],
            ),
          ),

          Visibility(
            visible: false,
            child: Positioned(
                top: 15.w,
                right: 1.w,
                child: InkWell(
                  onTap: () {},
                  child: Container(
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                        borderRadius: const BorderRadius.only(
                          topLeft: Radius.circular(30.0),
                          bottomLeft: Radius.circular(30.0),
                        ),
                        color: Tools.fromHex("#F9541E")),
                    width: 87.w,
                    height: 32.w,
                    child: Text("玩法详情", style: setTextStyle(14, FontWeight.w400, Tools.fromHex("#FFFFFF"))),
                  ),
                )),
          )
        ],
      );
    });
  }
}

//助力列表ITEM
class helpListItem extends StatelessWidget {
  const helpListItem({
    super.key,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      height: 60.w,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Row(
            children: [
              BaseImage(url: "verify_code.png", width: 38.w, height: 38.w),
              SizedBox(width: 8.w),
              Column(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [Text("小姐姐", style: setTextStyle(14, FontWeight.w400, Tools.fromHex("#3D3D3D"))), Text("不错 挺有嚼劲的 也挺好吃", style: setTextStyle(12, FontWeight.w400, Tools.fromHex("#999999")))],
              ),
            ],
          ),
          //右边
          Row(
            children: [
              Text("砍掉", style: setTextStyle(12, FontWeight.w400, Tools.fromHex("#FF955D"))),
              Text("15.98", style: setTextStyle(12, FontWeight.w400, Tools.fromHex("#F83F2D"))),
              Text("元", style: setTextStyle(12, FontWeight.w400, Tools.fromHex("#FF955D"))),
            ],
          )
        ],
      ),
    );
  }
}
